/*
 * ColaDeEntrada.h
 *
 *  Created on: 20/05/2012
 *      Author: Shazgath
 */

#ifndef COLADEENTRADA_H_
#define COLADEENTRADA_H_

#include <queue>
#include "common_Socket.h"
#include "common_Mutex.h"

template <typename T>

class Cola {
	Mutex mut;
public:
	Cola() {
	}
	virtual ~Cola() {

	}
	void push(T cons) {
		Lock l(mut);
		elems.push(cons);
		l.broad();
	}
	T pop() {
		Lock l(mut);
		if(elems.size() == 0)
			l.wait();
		if(elems.size() == 0)
			throw(1);
		T e = elems.front();
		elems.pop();
		return e;
	}
	void broadcast() {
		Lock l(mut);
		l.broad();
	}
	void comenzar();
private:
	std::queue<T> elems;
};

#endif /* COLADEENTRADA_H_ */
